/*
 *   TroopSpeed.java
 * 	 @Author Oleg Gorobets
 *   Created: Jan 15, 2009
 *   CVS-ID: $Id: 
 *************************************************************************/

package net.villonanny.type;

public class TroopSpeed {
	
	private static int karten_dimension = 400;
	
	public class TroopTribeType {
		TroopType troopType;
		TribeType tribeType;
	}
	
	/**
	 * Speed 3x servers!!!
	 * @param tribeType
	 * @param troopType
	 * @return
	 */
	public static int getSpeed(TribeType tribeType, TroopType troopType) {
		
		if (tribeType == TribeType.ROMANS) {
			switch (troopType) {
				case TROOP1: return 12;
				case TROOP2: return 10;
				case TROOP3: return 14;
				case TROOP4: return 32;
				case TROOP5: return 28;
				case TROOP6: return 20;
				case TROOP7: return 8; 
				case CATAPULT: return 6;
				case TROOP9: return 8;
				case TROOP10: return 10;
				default:
					throw new IllegalArgumentException("Invalid troop type: "  + troopType);
			}
		}
		
		if (tribeType == TribeType.TEUTONS) {
			switch (troopType) {
				case TROOP1: return 14;
				case TROOP2: return 14;
				case TROOP3: return 12;
				case TROOP4: return 18;
				case TROOP5: return 20;
				case TROOP6: return 18;
				case TROOP7: return 8; 
				case CATAPULT: return 6;
				case TROOP9: return 8;
				case TROOP10: return 10;
				default:
					throw new IllegalArgumentException("Invalid troop type: "  + troopType);
			}
		}
		
		if (tribeType == TribeType.GAULS) {
			switch (troopType) {
				case TROOP1: return 14;
				case TROOP2: return 12;
				case TROOP3: return 34;
				case TROOP4: return 38;
				case TROOP5: return 32;
				case TROOP6: return 26;
				case TROOP7: return 8; 
				case CATAPULT: return 6;
				case TROOP9: return 10;
				case TROOP10: return 10;
				default:
					throw new IllegalArgumentException("Invalid troop type: "  + troopType);
			}
		}
		
		
		
		throw new IllegalArgumentException("Invalid tribe type: "  + tribeType);
		
		
	}
	
	private static int karten_distanz(int a, int b) {
//		flag_uebergang = false;
		int d = Math.abs(a-b);
		if (d<=karten_dimension) return d;
		// Uebergang am Kartenrand:
//		flag_uebergang = true;
		return Math.abs(d-(2*karten_dimension+1));
	}
	
	public static double karten_distanz(int x1, int y1,int x2, int y2) {
		
		int dx = karten_distanz(x1,x2);
		int dy = karten_distanz(y1,y2);
		
		double distanz = Math.sqrt(dx*dx + dy*dy);
		return distanz;

	}
	
	public static int karten_seconds(TribeType tribeType, TroopType troopType, double distance) {
		return karten_seconds(getSpeed(tribeType, troopType), distance);
	}
	
	public static int karten_seconds(int speed, double distance) {
		double hours = distance / (double)speed;
		double seconds = hours * 3600;
		return (int)Math.round(seconds);

	}
	
	public static void main(String[] args) {
//		double d = karten_distanz(-52,-107, -45, -102);
//		double sec = karten_seconds(TribeType.ROMANS, TroopType.TROOP4, d); 
//		System.out.println(d);
//		System.out.println(sec);
	}
	

	
}
